<?php error_reporting(E_ALL ^ E_NOTICE);?>
<?php require_once('../Connections/tech.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_tech, $tech);
$query_user_request = "SELECT * FROM student";
$user_request = mysql_query($query_user_request, $tech) or die(mysql_error());
$row_user_request = mysql_fetch_assoc($user_request);
$totalRows_user_request = mysql_num_rows($user_request);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['user_name'])) {
  $loginUsername=$_POST['user_name'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "registration.php";
  $MM_redirectLoginFailed = "log_in.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_tech, $tech);
  
  $LoginRS__query=sprintf("SELECT user_name, password FROM student WHERE user_name=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $tech) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>login</title>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Log-In</title>
<style type="text/css">
A.ex1:link { text-decoration:none; color:#06F;}
A.ex1:visited { text-decoration:none; color:#FCF;}
A.ex1:hover { text-decoration:underline; color:#3F0;}
</style>
</head>

<body bgcolor="#000000">
<form ACTION="<?php echo $loginFormAction; ?>"  method="POST" enctype="multipart/form-data" name="log_in" target="_self" id="log_in">
<table width="75%" border="0" align="center" bgcolor="#980000"  cellpadding="9" cellspacing="3">
  <tr width="500" height="100">
     <td colspan="4" rowspan="2" background='4.jpg'>
    </td>
    </tr>
    <tr>
    <tr>
    <td width="39%" height="36" align="right" valign="top" size="30%">
    <font size="5" color="#ffffff">
    User Name:
    </font>
    </td>
          <td>
      <input name="user_name" type="text" id="user_name" value="" size="50" /></td>
    </tr>
    <tr>
     <td width="39%" height="36" align="right" valign="top" size="30%">
    <font size="5" color="#ffffFF">
     Password:
    </font>
    </td>
     <td><input name="password" type="password" id="password" size="50" /></td>
  </tr>
   <tr><td></td></tr>
    <tr><td></td></tr>
  
    <tr>
      <td><?php echo $errormsg ;?></td>
      <td><input type="submit" name="Log_in" id="Log_in" value=" Log-In " style="background:#FCF" /></td></tr>
      <tr> <td>&nbsp;</td>
<tr>
      <td><?php echo $errormsg ;?></td>
      <td><input type="submit" name="create new account" id="create" value=" create new account " style="background:#FCF" /></td></tr>
      <tr> <td>&nbsp;</td>
      <td></td>
    </tr>
    <tr><td></td></tr>
     <tr><td></td></tr>
    <tr><td></td></tr>
     <tr><td></td></tr>
    
  
     <tr >
      <td align="center" colspan="2">
<font face="Snap ITC" size="3" color="#ffffff">
<B>
<h3 align="center"> CopyRight© 2014</h3>
      </B>
      </font>
      </td></tr>
  </table>
</form>


</body>
</html>
<?php
mysql_free_result($user_request);
?>
